﻿package view.player
{
	import flash.display.MovieClip;
	import flash.display.Shape;
	import view.monsters.*;
	//[Embed(source="../../lib/TimeSaver.swf", symbol="classes.CommonBehaven")]
	public class CommonBehave extends MovieClip
	{
		public static var STATE_STOP:int = 0;
		public static var STATE_ATTACK:int = 1;
		public static var STATE_BEHIT:int = 2;
		public static var STATE_DEAD:int = 3;
		public static var STATE_MOVE:int = 4;
        public var m_nState:int = STATE_STOP;//当前状态
		
		public static var STATE_LEFT:int = 1;
		public static var STATE_RIGHT:int = 2;
		public static var STATE_UP:int = 3;
		public static var STATE_DOWN:int = 4;
		public var m_nMove:int = STATE_STOP//当前移动状态

		public var m_Speed:Number;//速度
		public var m_Attack:int;//攻击
		public var m_LastX:Number;//记录X
		public var m_LastY:Number;//记录Y
		public var attackBox:MovieClip;//攻击碰撞盒
		public var bodyBox:MovieClip;//身体碰撞盒
		
		public var bflag:Boolean = true;//能否跳跃

		public function CommonBehave():void
		{
			this.stop();
		}
		
		//设置状态
		public function setState(sta:int):void
		{
			m_nState = sta;
		}

        protected function FrameUpDate(startFrame:int,endFrame:int):void
		{
			if (this.currentFrame < startFrame || this.currentFrame >= endFrame)
			{
				gotoAndStop(startFrame);
			}
			else
			{
				nextFrame();
			}
		}
		
		protected function Move():void
		{
			m_LastX = this.x;
			m_LastY = this.y;
			switch(m_nMove)
			{
				case STATE_UP:
				      this.y = this.y - m_Speed;
					  break;
				case STATE_DOWN:
				      this.y = this.y + m_Speed;
					  break;
				case STATE_LEFT:
				      this.x = this.x - m_Speed;
					  break;
				case STATE_RIGHT:
				      this.x = this.x + m_Speed;
					  break;
				}
			//***************边沿检测*******************
			//ps:图片要规格2048*768,则this.x >= this.parent.width
			if(this.x < 0 || this.x > 2 * this.stage.stageWidth)
				MoveBack();
			if(this.y < 420 || this.y > this.stage.stageHeight)
			{
				if(bflag == true)
				    MoveBack();
			}
		}
		
		//退回上一次操作的位置
		public function MoveBack():void
		{
			this.x = m_LastX;
			this.y = m_LastY;
		}
		
		public function Behit(TLife:MovieClip,object:CommonBehave):Boolean
		{
			var life:int = Life(TLife).getCurLife();
			var PlayerAttack:int = object.m_Attack;//获取玩家攻击值
			life = (life - PlayerAttack);
			
			//m_TextLeft.text = String(PlayerAttack);
			//m_TextLeft.visible = true;
			TLife.setCurLife(life);
			setState(STATE_STOP);
			if(life <= 0)
			   return true;
			return false;
		}


	}

}